package com.sprouting.personal.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sprouting.personal.dao.TaskSignDetailDao;
import com.sprouting.personal.model.entity.TaskSign;
import com.sprouting.personal.dao.TaskSignDao;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sprouting.personal.model.entity.TaskSignDetail;
import com.sprouting.personal.model.vo.TaskSignVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 签到组 service接口实现
 *
 * @author ：sprouting
 * @date 创建时间： 2023-07-02 12:27:51
 */
@Service
@Slf4j
public class TaskSignService extends ServiceImpl<TaskSignDao, TaskSign> {

	@Resource
	private TaskSignDao taskSignDao;
	@Resource
	private TaskSignDetailDao taskSignDetailDao;



	/**
	 * 通过ID查询单条数据
	 * @param id 主键
	 * @return 签到组
	 */
	public TaskSign getTaskSignById(String id) {
		return taskSignDao.getTaskSignById(id);
	}

	/**
	 * 分页查询
	 * @param page 分页参数
	 * @param taskSign 查询参数
	 * @return 条件查询结果
	 */
	public Page<TaskSignVo> getTaskSignPage(Page page, TaskSign taskSign){
		return taskSignDao.getTaskSignPage(page, taskSign);
	}

	/**
	 * 根据主键删除签到表信息
	 * @param id 签到表主键
	 */
	public void delTaskSignById(String id) {
		taskSignDao.deleteById(id);

		LambdaQueryWrapper<TaskSignDetail> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(TaskSignDetail::getTaskSignId, id);
		taskSignDetailDao.delete(wrapper);
	}
}
